package com.pig4cloud.pig.bzg.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.bzg.entity.WzRecommendedColumnEntity;
import com.pig4cloud.pig.bzg.service.WzRecommendedColumnService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 推荐栏目表
 *
 * @author pig
 * @date 2025-08-04 10:15:37
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/wzRecommendedColumn" )
@Tag(description = "wzRecommendedColumn" , name = "推荐栏目表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class WzRecommendedColumnController {

    private final  WzRecommendedColumnService wzRecommendedColumnService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param wzRecommendedColumn 推荐栏目表
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    public R getWzRecommendedColumnPage(@ParameterObject Page page, @ParameterObject WzRecommendedColumnEntity wzRecommendedColumn) {
        return R.ok(wzRecommendedColumnService.selectRecommendedColumnList(page, wzRecommendedColumn));
    }


    /**
     * 通过id查询推荐栏目表
     * @param recommendedColumnId id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{recommendedColumnId}" )
    public R getById(@PathVariable("recommendedColumnId" ) Long recommendedColumnId) {
        return R.ok(wzRecommendedColumnService.getById(recommendedColumnId));
    }

    /**
     * 新增推荐栏目表
     * @param wzRecommendedColumn 推荐栏目表
     * @return R
     */
    @Operation(summary = "新增推荐栏目表" , description = "新增推荐栏目表" )
    @SysLog("新增推荐栏目表" )
    @PostMapping
    public R save(@RequestBody WzRecommendedColumnEntity wzRecommendedColumn) {
        return R.ok(wzRecommendedColumnService.save(wzRecommendedColumn));
    }

    /**
     * 修改推荐栏目表
     * @param wzRecommendedColumn 推荐栏目表
     * @return R
     */
    @Operation(summary = "修改推荐栏目表" , description = "修改推荐栏目表" )
    @SysLog("修改推荐栏目表" )
    @PutMapping
    public R updateById(@RequestBody WzRecommendedColumnEntity wzRecommendedColumn) {
        return R.ok(wzRecommendedColumnService.updateById(wzRecommendedColumn));
    }

    /**
     * 通过id删除推荐栏目表
     * @param ids recommendedColumnId列表
     * @return R
     */
    @Operation(summary = "通过id删除推荐栏目表" , description = "通过id删除推荐栏目表" )
    @SysLog("通过id删除推荐栏目表" )
    @DeleteMapping
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(wzRecommendedColumnService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param wzRecommendedColumn 查询条件
   	 * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    public List<WzRecommendedColumnEntity> export(WzRecommendedColumnEntity wzRecommendedColumn,Long[] ids) {
        return wzRecommendedColumnService.list(Wrappers.lambdaQuery(wzRecommendedColumn).in(ArrayUtil.isNotEmpty(ids), WzRecommendedColumnEntity::getRecommendedColumnId, ids));
    }
}